import {useParame,useLocation} from 'react-router-dom'
import qs from 'querystring'

let students=[
    {"id":1,"name":"张三","gender":"男","age":19},
    {"id":2,"name":"李四","gender":"女","age":21},
    {"id":3,"name":"李菊花","gender":"女","age":20},
]
//根据id获得学生详细信息
function getStudentById(stuid){
   // console.log("stuid===>",stuid)
    let obj= students.find(item=>item.id==stuid)
    //console.log("obj==>>",obj)
     return <div>
            编号：{obj.id}--姓名：{obj.name}--性别：{obj.gender}--年龄：{obj.age}
            </div> 
}


export default  (props)=>{

      //console.log(props)
    //显示获得参数
    //let {id} =props.match.params
   //let {stuid} = useParams();
    //console.log("stuid内部===>",stuid)
  //查询字符串
  //let {id} =qs.parse(props.location.search.slice(1));
  //console.log("obj==>>",obj)
   //state 传值
   //let {id} = props.location.state;
   let {id} = useLocation().state;

    return(
        <div>
            <h5>详细为：</h5>
             { getStudentById(id)}
        </div>
    )
}